<%@page import="com.xnx3.j2ee.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://www.xnx3.com/java_xnx3/xnx3_tld" prefix="x" %>
<jsp:include page="../../common/head.jsp">
	<jsp:param name="title" value="用户列表"/>
</jsp:include>
<style>
	img{
		width:30px;
		height:30px;	
	}
</style>
<script src="/<%=Global.CACHE_FILE %>Role_role.js"></script>

<jsp:include page="../../common/list/formSearch_formStart.jsp" ></jsp:include>
		<a class="layui-btn" onclick="getChengdanExecl();" style="float: left; margin-left: 50px;margin-bottom: 10px">导出excel</a>
</form>

<div class="tabox" style="padding:0 20px;min-width: 1200px;">
<table class="layui-table iw_table" style="min-width: 1200px;">
  <thead>
    <tr>
        <th style="width:80px; text-align:center">用户编号</th>
        <th style="width:80px; text-align:center">用户等级</th>
        <th style="width:200px; text-align:center">用户昵称</th>
        <th style="width:100px; text-align:center">用户手机号</th>
        <th style="width:100px; text-align:center">用户头像</th>
        <th style="width:80px; text-align:center">下单数</th>
        <th style="width:80px; text-align:center">总重量(kg)</th>
        <th style="width:80px; text-align:center">总金额(元)</th>
        <th style="width:150px; text-align:center">注册时间</th>
        <th style="width:80px; text-align:center">操作</th>    
    </tr> 
  </thead>
  <tbody>
  	<c:forEach items="${list}" var="user">
  		<tr>
          <td >${user.id }</td>
          <td >${user.grade }</td>
          <td >${user.nickname }</td>
          <td >${user.phone }</td>
          <td style="text-align:center;">
				<a href="${user.head}" target="_black"><img src = '${user.head }' /></a>
		  </td>
          <td>${user.allOrderNumbe }</td>
          <td>${user.allSellWgight /1000}</td>
          <td>${user.allIncomeMone /100}</td>
          <td><x:time linuxTime="${user.regtime }" format="yy-MM-dd HH:mm"></x:time></td>
          <td>
          		<botton class="layui-btn layui-btn-sm" onclick="editRole(${user.id }, '${user.nickname }');" style="margin-left: 3px;">订单记录</botton>
          </td>
      </tr>
    </c:forEach>
  </tbody>
</table>
</div>
<!-- 通用分页跳转 -->
<jsp:include page="../../common/page.jsp"></jsp:include>

<script type="text/javascript">
//根据id删除用户
function deleteUser(id,name){
	var dtp_confirm = layer.confirm('确定要删除用户“'+name+'”？删除后不可恢复！', {
	  btn: ['删除','取消'] //按钮
	}, function(){
		layer.close(dtp_confirm);

        parent.msg.loading("删除中");
		$.post('/admin/user/deleteUser.do?id='+id, function(data){
            parent.msg.close();
		    if(data.result == '1'){
		        parent.msg.success('操作成功')
		        window.location.reload();	//刷新当前页
		     }else if(data.result == '0'){
		         parent.msg.failure(data.info);
		     }else{
                parent.msg.failure('操作失败');
		     }
		});

	}, function(){
	});
}

//查看用户详情信息
function userView(id){
	layer.open({
		type: 2, 
		title:'查看用户信息', 
		area: ['460px', '630px'],
		shadeClose: true, //开启遮罩关闭
		content: '/admin/user/view.do?id='+id
	});
}

//订单记录
function editRole(id, nickname){
	layer.open({
		type: 2, 
		title:'订单记录', 
		area: ['90%','90%'],
		shadeClose: true, //开启遮罩关闭
		content: '/admin/user/orderList.jsp?userid='+id
	});
}

/**
 * 对象转url参数
 * @param {*} data,对象
 * @param {*} isPrefix,是否自动加上"?"
 */
function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets') {
    let prefix = isPrefix ? '?' : ''
    let _result = []
    if (['indices', 'brackets', 'repeat', 'comma'].indexOf(arrayFormat) == -1) arrayFormat = 'brackets';
    for (let key in data) {
        let value = data[key]
        // 去掉为空的参数
        if (['', undefined, null].indexOf(value) >= 0) {
            continue;
        }
        // 如果值为数组，另行处理
        if (value.constructor === Array) {
            // e.g. {ids: [1, 2, 3]}
            switch (arrayFormat) {
                case 'indices':
                    // 结果: ids[0]=1&ids[1]=2&ids[2]=3
                    for (let i = 0; i < value.length; i++) {
                        _result.push(key + '[' + i + ']=' + value[i])
                    }
                    break;
                case 'brackets':
                    // 结果: ids[]=1&ids[]=2&ids[]=3
                    value.forEach(_value => {
                        _result.push(key + '[]=' + _value)
                    })
                    break;
                case 'repeat':
                    // 结果: ids=1&ids=2&ids=3
                    value.forEach(_value => {
                        _result.push(key + '=' + _value)
                    })
                    break;
                case 'comma':
                    // 结果: ids=1,2,3
                    let commaStr = "";
                    value.forEach(_value => {
                        commaStr += (commaStr ? "," : "") + _value;
                    })
                    _result.push(key + '=' + commaStr)
                    break;
                default:
                    value.forEach(_value => {
                        _result.push(key + '[]=' + _value)
                    })
            }
        } else {
            _result.push(key + '=' + value)
        }
    }
    return _result.length ? prefix + _result.join('&') : ''
}


//导出execl
function getChengdanExecl(){
	var data = wm.getJsonObjectByForm($('.toubu_xnx3_search_form'));
	 window.open('/superadmin/outdoc/getUserExecl.json' + queryParams(data)); 
} 
</script>

<jsp:include page="../../common/foot.jsp"></jsp:include>